#!/bin/bash

    NEW_TAG=1.0.0
    PROJECT_NAME=rtms-admin
    PORT=8100
    echo ": 进入docker目录，删除 历史文件 "

    pwd
    sleep 1
    echo "--------------------- 删除老版本容器 ---------------------"
    docker rm -f  ${PROJECT_NAME}
    echo "--------------------- 删除老版本镜像 ---------------------"
    docker rmi -f ${HARBOR}/${PROJECT_NAME}:${NEW_TAG}
    rm -rf ./dist
    echo "--------------------- 创建镜像 ---------------------"
    cp -r ../dist dist
    cd docker
    pwd
    docker build -t ${PROJECT_NAME}:${NEW_TAG} --build-arg envType=prod .

    echo "--------------------- 创建新版本容器 ---------------------"


    mkdir -p /data/log/${PROJECT_NAME}
    # 创建新容器
    docker run -d -p ${PORT}:80  \
      --name ${PROJECT_NAME} \
      --restart always \
      --net=bridge \
      -v /data/log/${PROJECT_NAME}:/var/log/nginx \
      ${PROJECT_NAME}:${NEW_TAG}

#
#SOURCE_PATH=$(
#  cd $(dirname $0)
#  pwd
#)
#rm -rf $SOURCE_PATH/JZdist
#mkdir -p $SOURCE_PATH/JZdist
#sudo tar -zxvf JZdist.tar.gz -C JZdist
#cd JZdist/docker
#
#sudo docker -v
#
#echo "： 停止历史容器，删除历史容器和镜像"
#CID=$(docker ps -a | grep "etag-admin" | awk '{print $1}')
#if [ -n "$CID" ]; then
#  echo "存在 etag-admin 容器，CID=$CID,删除docker容器 ..."
#  docker stop $CID
#  sleep 1
#  docker rm -f $CID
#  echo "成功删除 etag-admin 容器  $CID"
#else
#  echo "不存在 etag-admin 容器"
#fi
#sleep 1
##镜像id
#IID=$(docker images | grep "etag-admin" | awk '{print $3}')
#if [ -n "$IID" ]; then
#  echo "存在 etag-admin 镜像，IID=$IID ，准备强制删除 "
#  docker rmi -f $IID
#  echo "成功删除 etag-admin $IID 镜像"
#fi


#rm $SOURCE_PATH/JZdist.tar.gz
